<?php

/**
 * contact : 刘经理 19326416371
 * company : 版权所属 四川北星惯牌科技有限公司
 **/

namespace app\common\model;

use think\Model;


class Order extends Model
{
    CONST IS_BALANCE_YES = 1;
    CONST IS_BALANCE_NO = 0;


    const PAY_STATE_INIT = 0;
    const PAY_STATE_INIT_MESSAGE = '未支付';
    const PAY_STATE_SUCCESS = 1;
    const PAY_STATE_SUCCESS_MESSAGE = '成功';

    const PAY_STATE_FAIL = 2;
    const PAY_STATE_FAIL_MESSAGE = '失败';
    const PAY_STATE_EXPIRE = 3;
    const PAY_STATE_EXPIRE_MESSAGE = '超时';
    const PAY_STATE_CANCEL = 4;
    const PAY_STATE_CANCEL_MESSAGE = '取消';



    const PAY_STATE_ARRAY = [
        self::PAY_STATE_INIT=>[
            'name'=>self::PAY_STATE_INIT_MESSAGE,
            'value'=>self::PAY_STATE_INIT,
        ],
        self::PAY_STATE_SUCCESS=>[
            'name'=>self::PAY_STATE_SUCCESS_MESSAGE,
            'value'=>self::PAY_STATE_SUCCESS,
        ],
        self::PAY_STATE_FAIL=>[
            'name'=>self::PAY_STATE_FAIL_MESSAGE,
            'value'=>self::PAY_STATE_FAIL,
        ],
        self::PAY_STATE_EXPIRE=>[
            'name'=>self::PAY_STATE_EXPIRE_MESSAGE,
            'value'=>self::PAY_STATE_EXPIRE,
        ],
        self::PAY_STATE_CANCEL=>[
            'name'=>self::PAY_STATE_CANCEL_MESSAGE,
            'value'=>self::PAY_STATE_CANCEL,
        ]
    ];

    const IS_BASIC_YES = 1;
    const IS_BASIC_NO = 0;
    const TYPE_EXPRESS = 1;
    const TYPE_EXPRESS_MSG = '购买体验卡';
    const TYPE_MATCH = 2;
    const TYPE_MATCH_MSG = '赛事报名';
    const TYPE_TEAM = 3;
    const TYPE_TEAM_MSG = '组队报名';
    const TYPE_RECHARGE = 4;
    const TYPE_RECHARGE_MSG = '充值';

    const TYPE_ASSISTANT = 5;
    const TYPE_ASSISTANT_MSG = '助教';

    const TYPE_ARRAY = [
        self::TYPE_EXPRESS=>[
            'value'=> self::TYPE_EXPRESS,
            'name'=> self::TYPE_EXPRESS_MSG,
        ],

        self::TYPE_MATCH=>[
            'value'=> self::TYPE_MATCH,
            'name'=> self::TYPE_MATCH_MSG,
        ],

        self::TYPE_TEAM=>[
            'value'=> self::TYPE_TEAM,
            'name'=> self::TYPE_TEAM_MSG,
        ],

        self::TYPE_RECHARGE=>[
            'value'=> self::TYPE_RECHARGE,
            'name'=> self::TYPE_RECHARGE_MSG,
        ],

        self::TYPE_ASSISTANT=>[
            'value'=> self::TYPE_ASSISTANT,
            'name'=> self::TYPE_ASSISTANT_MSG,
        ],
    ];

    // 表名
    protected $name = 'pay_order';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = false;

    // 定义时间戳字段名
    protected $createTime = false;
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'pay_state_text',
        'type_text',
        'delete_text'
    ];
    

    
    public function getPayStateList()
    {
        return ['0' => __('Pay_state 0'), '1' => __('Pay_state 1'), '2' => __('Pay_state 2'), '3' => __('Pay_state 3'), '4' => __('Pay_state 4')];
    }

    public function getTypeList()
    {
        return ['1' => __('Type 1'), '2' => __('Type 2'), '3' => __('Type 3'), '4' => __('Type 4')];
    }

    public function getDeleteList()
    {
        return ['0' => __('Delete 0'), '1' => __('Delete 1')];
    }


    public function getPayStateTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['pay_state']) ? $data['pay_state'] : '');
        $list = $this->getPayStateList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getTypeTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['type']) ? $data['type'] : '');
        $list = $this->getTypeList();
        return isset($list[$value]) ? $list[$value] : '';
    }


    public function getDeleteTextAttr($value, $data)
    {
        $value = $value ? $value : (isset($data['delete']) ? $data['delete'] : '');
        $list = $this->getDeleteList();
        return isset($list[$value]) ? $list[$value] : '';
    }




    public function user()
    {
        return $this->belongsTo('User', 'user_id', 'id', [], 'LEFT')->setEagerlyType(0);
    }
}
